# -*- coding:utf-8 -*-
# @Author: shenyuyu
# @Time: 2023/6/26 10:42
# @File: qu_1_groupbykey.py

from pyspark import SparkConf, SparkContext

if __name__ == '__main__':
    conf = SparkConf().setAppName("a").setMaster("local[*]")
    sc = SparkContext(conf=conf)
    rdd1 = sc.parallelize([('c', 3), ('f', 1), ('b', 11), ('c', 3), ('B', 1), ('c', 5), ('e', 1), ('n', 9), ('a', 1)])
    rdd2 = rdd1.groupByKey()
    print(rdd2.map(lambda x: (x[0], sum(list(x[1])))).collect())